<template>
	<view class="profile-page">
		<view class="profile-header">
		<view class="user-info">
			<view class="user-avatar">
				<image v-if="userInfo.avatar" :src="userInfo.avatar" class="avatar-img" mode="aspectFill" />
				<text v-else class="avatar-text">{{ userInfo.name.charAt(0) }}</text>
			</view>
				<view class="user-details">
					<text class="user-name">{{ userInfo.name }}</text>
					<text class="user-role">{{ userInfo.role }}</text>
				<text class="user-id">ID: {{ userInfo.id }}</text>
				</view>
			</view>
		</view>

		<view class="stats-section">
			<view class="stats-grid">
				<view class="stats-item">
					<text class="stats-number">{{ userStats.checkinDays }}</text>
					<text class="stats-label">签到天数</text>
				</view>
				<view class="stats-item">
					<text class="stats-number">{{ userStats.dynamicCount }}</text>
					<text class="stats-label">发布动态</text>
				</view>
				<view class="stats-item">
					<text class="stats-number">{{ userStats.likeCount }}</text>
					<text class="stats-label">获得点赞</text>
				</view>
			</view>
		</view>

		<view class="menu-section">
			<view class="menu-group">
				<view class="menu-item" @click="navigateTo('/pages/profile/edit')">
					<view class="menu-icon">
						<text class="icon-text">✏️</text>
					</view>
					<text class="menu-text">编辑资料</text>
					<text class="menu-arrow">></text>
				</view>
				<view class="menu-item" @click="navigateTo('/pages/profile/settings')">
					<view class="menu-icon">
						<text class="icon-text">⚙️</text>
					</view>
					<text class="menu-text">设置</text>
					<text class="menu-arrow">></text>
				</view>
			</view>

			<view class="menu-group">
				<view class="menu-item" @click="navigateTo('/pages/profile/achievements')">
					<view class="menu-icon">
						<text class="icon-text">🏆</text>
					</view>
					<text class="menu-text">我的成就</text>
					<text class="menu-arrow">></text>
				</view>
				<view class="menu-item" @click="navigateTo('/pages/profile/notifications')">
					<view class="menu-icon">
						<text class="icon-text">🔔</text>
					</view>
					<text class="menu-text">消息通知</text>
					<view class="notification-badge" v-if="unreadCount > 0">
						<text class="badge-text">{{ unreadCount }}</text>
					</view>
					<text class="menu-arrow">></text>
				</view>
			</view>

			<view class="menu-group">
				<view class="menu-item" @click="navigateTo('/pages/profile/help')">
					<view class="menu-icon">
						<text class="icon-text">❓</text>
					</view>
					<text class="menu-text">帮助中心</text>
					<text class="menu-arrow">></text>
				</view>
				<view class="menu-item" @click="navigateTo('/pages/profile/about')">
					<view class="menu-icon">
						<text class="icon-text">ℹ️</text>
					</view>
					<text class="menu-text">关于我们</text>
					<text class="menu-arrow">></text>
				</view>
			</view>
		</view>

		<view class="logout-section">
			<view class="logout-button" @click="handleLogout">
				<text class="logout-text">退出登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { getStoredUser, clearAuth } from '@/utils/auth';

	export default {
		data() {
			return {
				userInfo: {
					name: '创数成员',
					role: '团队成员',
					id: '--',
					avatar: ''
				},
				userStats: {
					checkinDays: 25,
					dynamicCount: 12,
					likeCount: 48
				},
				unreadCount: 3
			};
		},
		onShow() {
			this.loadUserInfo();
		},
		methods: {
			loadUserInfo() {
				const stored = getStoredUser();
				if (stored) {
					this.userInfo = {
						name: stored.nickname || stored.name || '创数成员',
						role: stored.direction || '团队成员',
						id: stored.id || '--',
						avatar: stored.avatarUrl || stored.avatar || ''
					};
				} else {
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			},
			navigateTo(url) {
				uni.showToast({
					title: '功能开发中...',
					icon: 'none'
				});
			},
			handleLogout() {
				uni.showModal({
					title: '确认退出',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							clearAuth();
							uni.showToast({
								title: '已退出登录',
								icon: 'success'
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/login/login'
								});
							}, 300);
						}
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.profile-page {
		min-height: 100vh;
		background: #f9fafb;
	}

	.profile-header {
		background: linear-gradient(135deg, #6366f1, #8b5cf6);
		padding: 60rpx 40rpx 40rpx;
		color: #ffffff;
	}

	.user-info {
		display: flex;
		align-items: center;
	}

	.user-avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.2);
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 24rpx;
	}

	.avatar-img {
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}

	.avatar-text {
		font-size: 48rpx;
		font-weight: bold;
		color: #ffffff;
	}

	.user-details {
		flex: 1;
	}

	.user-name {
		display: block;
		font-size: 36rpx;
		font-weight: bold;
		margin-bottom: 8rpx;
	}

	.user-role {
		display: block;
		font-size: 26rpx;
		opacity: 0.9;
		margin-bottom: 4rpx;
	}

	.user-id {
		display: block;
		font-size: 22rpx;
		opacity: 0.7;
	}

	.stats-section {
		background: #ffffff;
		margin: -20rpx 40rpx 40rpx;
		border-radius: 16rpx;
		padding: 32rpx;
		box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
	}

	.stats-grid {
		display: grid;
		grid-template-columns: 1fr 1fr 1fr;
		gap: 20rpx;
	}

	.stats-item {
		text-align: center;
	}

	.stats-number {
		display: block;
		font-size: 48rpx;
		font-weight: bold;
		color: #6366f1;
		margin-bottom: 8rpx;
	}

	.stats-label {
		display: block;
		font-size: 22rpx;
		color: #6b7280;
	}

	.menu-section {
		padding: 0 40rpx;
		margin-bottom: 40rpx;
	}

	.menu-group {
		background: #ffffff;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
		box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
	}

	.menu-item {
		display: flex;
		align-items: center;
		padding: 32rpx;
		border-bottom: 1rpx solid #f3f4f6;
		transition: background-color 0.2s ease;
	}

	.menu-item:last-child {
		border-bottom: none;
	}

	.menu-item:active {
		background-color: #f9fafb;
	}

	.menu-icon {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
		background: #f3f4f6;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
	}

	.icon-text {
		font-size: 28rpx;
	}

	.menu-text {
		flex: 1;
		font-size: 28rpx;
		color: #1f2937;
	}

	.notification-badge {
		background: #ef4444;
		border-radius: 20rpx;
		padding: 4rpx 12rpx;
		margin-right: 12rpx;
		min-width: 32rpx;
		text-align: center;
	}

	.badge-text {
		font-size: 20rpx;
		color: #ffffff;
		font-weight: bold;
	}

	.menu-arrow {
		font-size: 24rpx;
		color: #9ca3af;
	}

	.logout-section {
		padding: 0 40rpx 60rpx;
	}

	.logout-button {
		background: #ffffff;
		border-radius: 16rpx;
		padding: 32rpx;
		text-align: center;
		box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
		transition: all 0.3s ease;
	}

	.logout-button:active {
		transform: translateY(2rpx);
		box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1);
	}

	.logout-text {
		font-size: 28rpx;
		font-weight: bold;
		color: #ef4444;
	}
</style>


